package com.github.wui.ViewEx

import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager


/**
 * 设置 RecyclerView 线性布局管理器
 */
fun RecyclerView.linear(): RecyclerView {
    this.layoutManager = LinearLayoutManager(this.context);
    return this;
}

fun RecyclerView.horizontalGrid(rowItems: Int): RecyclerView {
    this.layoutManager = GridLayoutManager(this.context, rowItems, RecyclerView.HORIZONTAL, false);
    return this
}


fun RecyclerView.horizontalLinear(): RecyclerView {
    this.layoutManager = LinearLayoutManager(this.context, RecyclerView.HORIZONTAL, false);
    return this
}


fun RecyclerView.horizontalGridReverse(rowItems: Int): RecyclerView {
    this.layoutManager = GridLayoutManager(this.context, rowItems, RecyclerView.HORIZONTAL, true);
    return this
}


fun RecyclerView.verticalGridReverse(rowItems: Int): RecyclerView {
    this.layoutManager = GridLayoutManager(this.context, rowItems, RecyclerView.VERTICAL, true);
    return this;
}

fun RecyclerView.verticalGrid(rowItems: Int): RecyclerView {
    this.layoutManager = GridLayoutManager(this.context, rowItems, RecyclerView.VERTICAL, false);
    return this
}


fun RecyclerView.horizontalStaggered(spanCount: Int): RecyclerView {
    this.layoutManager = StaggeredGridLayoutManager(spanCount, RecyclerView.HORIZONTAL)
    return this;
}

fun RecyclerView.verticalStaggered(spanCount: Int): RecyclerView {
    this.layoutManager = StaggeredGridLayoutManager(spanCount, RecyclerView.HORIZONTAL)
    return this;
}


